//
//  BKMianXueFeiViewController.m
//  baokaodaxue
//
//  Created by SKar on 15/6/2.
//  Copyright (c) 2015年 宏图教育. All rights reserved.
//

#import "BKMianXueFeiViewController.h"
#import "BKSearchField.h"
#import "BKMianXueFeiViewModel.h"
#import "BKResultOfMianXueFeiViewController.h"
#import <MBProgressHUD.h>
#import "BKButton.h"
@interface BKMianXueFeiViewController ()
@property (weak, nonatomic) IBOutlet BKButton *benke;
@property (weak, nonatomic) IBOutlet BKButton *zhuanke;
@property (weak, nonatomic) IBOutlet BKSearchField *wenli;


@property (weak, nonatomic) IBOutlet BKSearchField *schoolLocationTextField;
@property (weak, nonatomic) IBOutlet BKSearchField *typeTextField;
@property (weak, nonatomic) IBOutlet BKSearchField *buzhuTextField;

@property (nonatomic, strong) BKMianXueFeiViewModel *viewModel;

@end

@implementation BKMianXueFeiViewController

- (instancetype)initWithNib {
    self = [super initWithNibName:NSStringFromClass([BKMianXueFeiViewController class]) bundle:nil];
    if (self) {
        _viewModel = [[BKMianXueFeiViewModel alloc] init];
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    _wenli.dataArray = @[@"文科",@"理科"];
    _wenli.flag = 8011;
    _schoolLocationTextField.dataArray = @[
                                 @"不限",
                                 @"北京",
                                 @"天津",
                                 @"上海",
                                 @"重庆",
                                 @"河北",
                                 @"河南",
                                 @"山东",
                                 @"山西",
                                 @"安徽",
                                 @"江西",
                                 @"江苏",
                                 @"浙江",
                                 @"湖北",
                                 @"湖南",
                                 @"广东",
                                 @"广西",
                                 @"云南",
                                 @"贵州",
                                 @"四川",
                                 @"陕西",
                                 @"青海",
                                 @"宁夏",
                                 @"黑龙江",
                                 @"吉林",
                                 @"辽宁",
                                 @"西藏",
                                 @"新疆",
                                 @"内蒙古",
                                 @"海南",
                                 @"福建",
                                 @"甘肃"];
    _schoolLocationTextField.flag = 8011;
    
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    if ([userDefaults objectForKey:@"dq"]) {
        _schoolLocationTextField.text = [userDefaults objectForKey:@"dp"];
    }
    [_benke setSelected:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)submit:(id)sender {
    __weak typeof(self) weakSelf = self;
    
    if ([_schoolLocationTextField.text length]>0) {
        NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
        [userDefaults setObject:_schoolLocationTextField.text forKey:@"dq"];
    }
    
    MBProgressHUD *hud = [[MBProgressHUD alloc] initWithView:self.view];
    [self.view addSubview:hud];
    hud.mode = MBProgressHUDModeIndeterminate;
    hud.labelText = @"正在加载";
    [hud show:YES];

    NSString *benzhuan ;
    if (_benke.selected) {
        benzhuan = @"本科";
    }else{
    
        benzhuan = @"专科";
    }
    [self.viewModel colleageWithPc:benzhuan dq:_schoolLocationTextField.text lx:_buzhuTextField.text success:^(NSArray *dataArray) {
                           __strong typeof(weakSelf) strongSelf = weakSelf;
                           dispatch_async(dispatch_get_main_queue(), ^{
                               [hud hide:YES];
                               [hud removeFromSuperview];
                               BKResultOfMianXueFeiViewController *vc = [[BKResultOfMianXueFeiViewController alloc] initWithNibByArray:dataArray];
                               [strongSelf.navigationController pushViewController:vc animated:YES];
                           });
                       } failure:^(NSString *message) {
                           dispatch_async(dispatch_get_main_queue(), ^{
                               [hud hide:YES];
                               [hud removeFromSuperview];
                               UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:message delegate:nil cancelButtonTitle:@"好的" otherButtonTitles:nil, nil];
                               [alertView show];
                           });
                       }];
}
- (IBAction)p_back:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}
- (IBAction)benzhuan:(id)sender {
    if ([sender isEqual:_benke]) {
        [_benke setSelected:YES];
        [_zhuanke setSelected:NO];
    }else{
    
        [_benke setSelected:NO];
        [_zhuanke setSelected:YES];
    }
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
